﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace MapServer
{
    public class JsonParameters
    {
        /// <summary>
        /// 反回JSON数据到前台
        /// </summary>
        /// <param name="dt">数据表</param>
        /// <returns>JSON字符串</returns>   
        /// <author>william</author>
        /// <createtime>2011-7-1</createtime>
        /// <remarks></remarks>
        public static string CreateJsonParameters(String sType,String sValue)
        {
            StringBuilder JsonString = new StringBuilder();
            sType = sType.Trim();
            sValue = sValue.Trim();
        
            JsonString.Append("{");
            JsonString.Append("\"code\":");
            JsonString.Append("\""+sValue+"\"");
            JsonString.Append("}");
            return JsonString.ToString();
        }

        public static string CreateJsonParameters(String sType, String sValue,String[] sValueList)
        {
            StringBuilder JsonString = new StringBuilder();
            sType = sType.Trim();
            sValue = sValue.Trim();
          
                JsonString.Append("{");
                JsonString.Append("\"code\":");
                JsonString.Append("\"" + sValue + "\"");
                if (sValueList.Length != 0)
                {
                    JsonString.Append(",\"dataList\":");
                    JsonString.Append("[");
                    for (int i = 0; i < sValueList.Length; i++)
                    {
                        //JsonString.Append("{");
                        JsonString.Append(sValueList[i]);
                        //JsonString.Append("}");
                        if (i != sValueList.Length - 1)
                        {
                            JsonString.Append(",");
                        }
                    }
                    JsonString.Append("]");
                }
                JsonString.Append("}");
                return JsonString.ToString();
           
        }
    }
}
